#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>

#include "sparse_node.h"

using namespace std;

void sparse_node_v1::update_xml_node(xml_node *node, const char *file_name, const char *label, DWORD base_sector)
{
	char buffer[128];
	
	node->set_type(CLOSED_NODE);
	node->set_name("program");

	node->set_val("file_sector_offset", "0");
	
	string val(file_name);
	int pos = max(val.find_last_of("\\"), val.find_last_of("/"));
	node->set_val("filename", val.substr(pos + 1, val.length() - pos - 1));

	node->set_val("label", label);

	_i64toa((__int64)(data_length / SECTOR_SIZE), buffer, 10);
	node->set_val("num_partition_sectors", buffer);

	node->set_val("physical_partition_number", "0");

	node->set_val("size_in_KB", "4");

	node->set_val("sparse", "false");

	_i64toa((__int64)(base_sector * SECTOR_SIZE + start_pos), buffer, 10);
	node->set_val("start_byte_hex", buffer);

	_i64toa((__int64)(base_sector + start_pos / SECTOR_SIZE), buffer, 10);
	node->set_val("start_sector", buffer);
}

